home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 501-525 / disk_519 / oaklisp / src.lzh / mymalloc.c < prev    next >
C/C++ Source or Header  |  1991-06-15  |  2KB  |  89 lines

  1. /*  Copyright (C) 1987 Barak Pearlmutter and Kevin Lang    */
  2.  
  3. #include <stdio.h>
  4. #include "emulator.h"
  5.  
  6. #ifdef PROTOTYPES
  7. extern void free_space(space *pspace);
  8. extern void alloc_space(space *pspace);
  9. extern char *my_malloc(long i);
  10. #endif
  11.  
  12.  
  13.  
  14. char *my_malloc(i)
  15.      long i;
  16. {
  17. #ifdef Mac_LSC
  18.   char *p;
  19.   ResrvMem(i);
  20.   p = mlalloc(i);
  21. #else
  22. #ifdef unix
  23.   char *p = malloc((unsigned)i);
  24. #else
  25.   char *p = malloc(i);
  26. #endif
  27. #endif
  28.  
  29.   if (p == NULL)
  30.     {
  31.       (void)fprintf(stderr, "\nUnable to allocate %ld bytes.\n", i);
  32.       exit(1);
  33.     }
  34.  
  35.   return p;
  36. }
  37.  
  38.  
  39. void realloc_space(pspace, pfree)
  40.      space *pspace;
  41.      ref *pfree;
  42. {
  43.   long new_size = pfree - pspace->start;
  44.   pspace->size = new_size;
  45.   pspace->end = pspace->start + new_size;
  46.   /* realloc commented out because it might move the block, even though
  47.      it's sure to be shrunk. */
  48.   /* realloc((char *)pspace->start, sizeof(ref)*new_size); */
  49. }
  50.  
  51.  
  52.  
  53. void free_space(pspace)
  54.      space *pspace;
  55. {
  56. #ifdef UNALIGNED
  57.   free((char *)pspace->start - pspace->offset);
  58.   if (pspace->offset)
  59.     pspace->size += 1;
  60. #else
  61.   free((char *)pspace->start);
  62. #endif
  63.  
  64.   pspace->start = pspace->end = NULL;
  65. }
  66.  
  67.  
  68.  
  69.  
  70. void alloc_space(pspace)
  71.      space *pspace;
  72. {
  73.   char *p = my_malloc(sizeof(ref) * pspace->size);
  74.  
  75. #ifdef UNALIGNED
  76.   pspace->offset = (long)p & 3L;
  77.   p = (char *) ((long)p + pspace->offset);
  78.   if (pspace->offset)
  79.     pspace->size -= 1;
  80. #endif
  81.  
  82.   /*NOSTRICT*/
  83.   pspace->start = (ref *) p;
  84.   pspace->end = pspace->start + pspace->size;
  85. }
  86.  
  87.  
  88.  
  89.